﻿@model DAL.User
@*<p>
    Please enter your user name and password. @Html.ActionLink("Register", "Register") if you don't have an account.
</p>*@
@*<script src="../../Scripts/jquery-1.8.2.min.js" type="text/javascript"></script>*@
<link href="../../Content/Styles/Site.css" rel="stylesheet" type="text/css" />
<link href="../../Content/Styles/button.css" rel="stylesheet" type="text/css" />
<link href="../../Content/Styles/login.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" language="javascript">
    //even đóng dialog khi click vào nút đóng
    $('.closelogin').click(function (e) {
        //hủy bỏ các link liên kết,"bỏ dấu #"
        e.preventDefault();
        //đóng thẻ dialog
        $("#dialog").fadeOut(500);
        //đóng thẻ nền dialog
        $("#dialog_nen").fadeOut(500);
        var url = window.location.href;
        if(url.indexOf("CreateStep1")!=-1) {
            window.location.href = "/Home/Index";
        }
       
    });
    $(document).keydown(function (e) {
        // ESCAPE key pressed
        if (e.keyCode == 27) {
            //hủy bỏ các link liên kết,"bỏ dấu #"
            e.preventDefault();
            //đóng thẻ dialog
            $("#dialog").fadeOut(500);
            //đóng thẻ nền dialog
            $("#dialog_nen").fadeOut(500);
        }
    });

</script>
@*@using (Html.BeginForm("CheckLogin", "UserRoles", FormMethod.Post, new { enctype = "multipart/form-data", id = "formLogin" }))
{*@

    <div id="Container">
        <div id="LoginWindow"  class="rounded-corners">
            <div id="LogoM"> <img src=".././../Content/images/icons/homefinal.jpg" width="50px" height="50px" alt="" />
                <div style="float: right;margin-right: 1px">
                    <a href="#"><img src="./../../Content/images/icons/close.png" class="closelogin"  width="30px" height="30px"/></a>
                </div>
                </div>
            
            <div class="logfield">
                <span class="leftspace" >Username</span>
                <input id="UsernameLogin" class="login-field" name="uname" type="text"  />           
            </div>
            <div class="logfield" style="width: 300px;">
                <span class="leftspace">Password</span>
                <input id="PasswordLogin" type="password" class="login-field" name="pass" type="text" />
            </div>
            <p>
                <input id="loginbtn" type="submit" class="small button green" style="width: 75px;height:30px;color:white !important"  value="Log On" />
                <input type="reset" class="small button green" style="margin-left: 5px;width: 75px;height:30px;color:white !important" value="Reset" id="resetbtn"/>
            </p>
           
                <div id="forgotpassword" style="margin-bottom: 10px;margin-left: 15px;margin-right: 10px; color: #1D95CB;text-decoration: underline;cursor: pointer; float: left">Forgot password?</div>
                <div style="float:left; margin-right: 10px">|</div>
            <div id="signup"style="margin-bottom: 20px;margin-left: 15px;color: #1D95CB;text-decoration: underline;cursor: pointer">Sign up</div>
            
        <div id="errorMsg"></div>
        </div>
     
    </div>
 

    
@*}*@
<script type="text/javascript">
    $(document).ready(function () {
        //focus
        document.getElementById('UsernameLogin').focus();
        //        String.prototype.trim = function () {
        //            return this.replace(/^\s+|\s+$/g, '');
        //        };
        $('#loginbtn').click(function () {
            var username = $('input#UsernameLogin').val();
            //var username = usernametemp.trim();
            var password = $('input#PasswordLogin').val();
            var url = window.location.href;
            if (username == "" || password == "") {
                $("div#errorMsg").css("display", "block");
                $("div#errorMsg").html("Please Enter Username, Password!");

            } else {//call ajax function here
                $.ajax({
                    url: "/Users/CheckUserLogin",
                    type: 'POST',
                    data: { usernameinput: username, password: password, url: "" },
                    success: function (response) {
                        //alert(response);
                        if (response == "Fail") {
                            $("div#errorMsg").css("display", "block");
                            $("div#errorMsg").html("Sorry,Username or password is not correct");
                            $('input#PasswordLogin').val('');

                        }
                        else {
                            $("#dialog").fadeOut(500);
                            //đóng thẻ nền dialog
                            $("#dialog_nen").fadeOut(500);
                            //history.go(0);
                            //                            $("#accountItem").css("display", "block");
                            //                            $("#usernamedisplay").html("Hi! "+username);
                            window.location.href = url;

                        }
                    }

                });


            }
        });
        $(document).keydown(function (e) {
            // ESCAPE key pressed
            if (e.keyCode == 13) {
                var username = $('input#UsernameLogin').val();
                var password = $('input#PasswordLogin').val();
                if (username == "" || password == "") {
                    $("div#errorMsg").css("display", "block");
                    $("div#errorMsg").html("Please Enter Username, Password!");
                } else {//call ajax function here
                    $.ajax({
                        url: "/Users/CheckUserLogin",
                        type: 'POST',
                        data: { usernameinput: username, password: password, url: "" },
                        success: function (response) {
                            //alert(response);
                            if (response == "Fail") {
                                $("div#errorMsg").css("display", "block");
                                $("div#errorMsg").html("Sorry,Username or password is not correct");

                            }
                            else {
                                $("#dialog").fadeOut(500);
                                //đóng thẻ nền dialog
                                $("#dialog_nen").fadeOut(500);
                                history.go(0);


                            }
                        }

                    });


                }


            }
        });
    });
    $('.close').click(function (e) {
        //hủy bỏ các link liên kết,"bỏ dấu #"
        e.preventDefault();
        //đóng thẻ dialog
        $("#dialog").fadeOut(500);
        //đóng thẻ nền dialog
        $("#dialog_nen").fadeOut(500);
    });
    $('#resetbtn').click(function () {
        document.getElementById('PasswordLogin').value = '';
        document.getElementById('UsernameLogin').value = '';
    });
    $('#signup').click(function (e) {
        e.preventDefault();
        $("#dialog").fadeOut(1);
        //đóng thẻ nền dialog
        $("#dialog_nen").fadeOut(1);
        $('a[data-ajax-update="#dialog"]')[1].click();
        $("#dialog_nen").fadeIn(500);
        //hiển thị dialog
        $("#dialog").fadeIn(500);
       //hiển thị hình nền		

    });
    $('#forgotpassword').click(function (e) {
        e.preventDefault();
        $("#dialog").fadeOut(1);
        //đóng thẻ nền dialog
        $("#dialog_nen").fadeOut(1);
        $('a[data-ajax-update="#dialog"]')[2].click();
        $("#dialog_nen").fadeIn(300);
        //hiển thị dialog
        $("#dialog").fadeIn(300);
        //hiển thị hình nền		

    });
</script>